package org.duang.email;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

import org.duang.common.exceptios.ServiceException;
import org.duang.kit.ToolsKit;

public class Authentication extends Authenticator{
	/**用户名(发送者邮箱地址)**/
    private String username;
    /**发送者邮箱密码**/
    private String password;

    public Authentication(String username, String password) {
        if(ToolsKit.isEmpty(username) || ToolsKit.isEmpty(password)){
            throw new ServiceException("username and password is required!");
        }

        this.username = username;
        this.password = password;
    }

    protected PasswordAuthentication getPasswordAuthentication(){
        return new PasswordAuthentication(username, password);
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
